package com.example.twoscroolview.view

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.core.view.ViewCompat
import androidx.viewpager.widget.ViewPager
import androidx.viewpager2.widget.ViewPager2

class CustomViewPageview: ViewPager {


    var startX = 0f
    var startY = 0f
    constructor(context: Context): super(context) {
    }

    constructor(context: Context, attrs: AttributeSet?): super(context, attrs) {
    }


    override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {

        when (ev?.action) {
            MotionEvent.ACTION_DOWN -> {
                startX=ev.x
                startY=ev.y
                ViewCompat.setNestedScrollingEnabled(this,true);
                parent.requestDisallowInterceptTouchEvent(true)
            }
            MotionEvent.ACTION_MOVE -> {
                val movex = ev.x-startX
                val movey = ev.y-startY

                if(Math.abs(movex)<Math.abs(movey)){
                    System.out.println("${Math.abs(movex)}-----"+Math.abs(movey))
                    parent.requestDisallowInterceptTouchEvent(false)
                }

            }
        }
        return super.dispatchTouchEvent(ev)
    }
}